const faultDao = require('../dao/fault');

const Response = require('../entity/http/Response');

const faultService = {
    async getAllfault(reqId, uid) {
        let result;
        try {
            let dbResult = await faultDao.getAllfault(reqId, uid);
            result = new Response().success(dbResult);
        } catch (err) {
            console.log(err);
            result = new Response().fail(500, "获取故障信息失败");
        }
        return result;
    },
    async deletefault(reqId, uid, id) {
        let result;
        try {
            let dbResult = await faultDao.deletefault(reqId, uid, id);
            if (dbResult.changedRows) {
                result = new Response().success("删除故障信息成功");
            } else {
                result = new Response().fail(500, "未查询到该故障信息");
            }
        } catch (err) {
            console.log(err);
            result = new Response().fail(500, "删除故障信息失败");
        }
        return result;
    },
    async readFault(reqId, uid, id) {
        let result;
        try {
            let dbResult = await faultDao.readFault(reqId, uid, id);
            if (dbResult.changedRows) {
                result = new Response().success("已读故障信息成功");
            } else {
                result = new Response().fail(500, "未查询到该故障信息");
            }
        } catch (err) {
            console.log(err);
            result = new Response().fail(500, "已读故障信息失败");
        }
        return result;
    }
};

module.exports = faultService;